package com.ewzj.bigdata

import android.content.Intent
import android.os.Bundle
import com.bigkoo.convenientbanner.ConvenientBanner
import com.ewzj.bigdata.app.config.AppKey
import com.ewzj.bigdata.app.extensions.DelegatesExt
import com.ewzj.bigdata.di.component.DaggerSplashComponent
import com.ewzj.bigdata.di.module.SplashModule
import com.ewzj.bigdata.mvp.contract.SplashContract
import com.ewzj.bigdata.mvp.presenter.SplashPresenter
import com.ewzj.bigdata.mvp.ui.activity.MainTabActivity
import com.jakewharton.rxbinding2.view.RxView
import com.jess.arms.base.BaseActivity
import com.jess.arms.di.component.AppComponent
import com.jess.arms.utils.DeviceUtils
import com.jess.arms.utils.UiUtils
import io.reactivex.functions.Action
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_splash.*
import java.util.concurrent.TimeUnit

class SplashActivity() : BaseActivity<SplashPresenter>(),SplashContract.View{
    var isFirst:Boolean by DelegatesExt.preference(this,AppKey.IS_FIRST,true)
    override fun showLoading() {

    }

    override fun launchActivity(intent: Intent?) {

    }

    override fun hideLoading() {

    }

    override fun killMyself() {

    }

    override fun showMessage(message: String?) {

    }

    override fun initView(savedInstanceState: Bundle?): Int {
        DeviceUtils.setFullScreen(this)
        return R.layout.activity_splash
    }

    override fun setupActivityComponent(appComponent: AppComponent) {
        DaggerSplashComponent.builder().appComponent(appComponent)
                .splashModule(SplashModule(this))
                .build()
                .inject(this)
    }

    override fun initData(savedInstanceState: Bundle?) {
        RxView.clicks(tv_first).throttleFirst(200,TimeUnit.MICROSECONDS)
                .subscribe(object :Consumer<Any>{
                    override fun accept(t: Any?) {
                        startActivity(Intent(this@SplashActivity,MainTabActivity::class.java))
                        isFirst=false
                        finish()
                    }
                })
        mPresenter.initBannner(banner as ConvenientBanner<Int>,tv_first)
    }

    override fun useFragment(): Boolean {
        return false
    }
}
